<template>
    <div>
        <h3>添加门店</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>店名</td>
                    <td><input type="text" v-model="a.DoorName"></td>
                </tr>
                <tr>
                    <td>营业时间</td>
                    <td><input type="date" v-model="a.StartTime">
                        -
                        <input type="date" v-model="a.EndTime">
                    </td>
                </tr>
                <tr>
                    <td>服务范围</td>
                    <td><select v-model="a.DoorType">
                            <option value="">请选择</option>
                            <option value="早餐早点">早餐早点</option>
                            <option value="炒菜炒饭">炒菜炒饭</option>
                            <option value="包办婚宴">包办婚宴</option>
                        </select></td>
                </tr>
                <tr>
                    <td>店主</td>
                    <td><input type="text" v-model="a.UserName"></td>
                </tr>
                <tr>
                    <td>联系电话</td>
                    <td><input type="text" v-model="a.Phone" maxlength="11"></td>
                </tr>
                <tr>
                    <td>门店介绍</td>
                    <td><textarea v-model="a.Desc"></textarea></td>
                </tr>
                <tr>
                    <td>门店地址</td>
                    <td><input type="text" v-model="a.Address"></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="radio" v-model="a.State" :value="1" name="state">启用
                        <input type="radio" v-model="a.State" :value="2" name="state">禁用
                    </td>
                </tr>
                <tr>
                    <td>门店logo</td>
                    <td><input type="file" @change="Imgss">
                        <img :src="a.DoorLogo" width="200">
                    </td>
                </tr>
                <tr>
                    <td>门店图片</td>
                    <td><input type="file" @change="Imgs">
                        <img :src="a.Photo" width="200">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="确定" @click="ok"></td>
                </tr>
            </tbody>
        </table>


    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

let a: any = reactive({
    DoorName: '',
    StartTime: '',
    EndTime: '',
    DoorType: '',
    UserName: '',
    Phone: '',
    Desc: '',
    Address: '',
    State: '',
    DoorLogo: '',
    Photo: '',
})

const ok: any = () => {
    if (a.DoorName == "") {
        alert("店名不能为空");
        return;
    }
    if (a.StartTime == "") {
        alert("开业时间不能为空");
        return;
    }
    if (a.EndTime == "") {
        alert("停业时间不能为空");
        return;
    }
    if (a.DoorType == "") {
        alert("服务范围不能为空");
        return;
    }
    if(a.Address=="")
    {
        alert("门店地址不能为空");
        return;
    }
    if(a.State=="")
    {
        alert("状态不能为空");
        return;
    }

    axios({
        url: '/api/ALL/AddDoor',
        method: 'post',
        data: a
    })
        .then((res) => {
            console.log(res);
            if (res.data > 0) {
                alert("添加成功");
                router.push("/doorshow");
            }
        })

}



const Imgs: any = (e: any) => {
    let obj = e.target.files[0]
    let f = new FormData();
    f.append('file', obj);
    axios({
        url: '/api/Img/UpImg',
        method: 'post',
        data: f
    })
        .then((res) => {
            a.Photo = res.data
        })
}

const Imgss: any = (e: any) => {
    let obj = e.target.files[0]
    let f = new FormData();
    f.append('file', obj);
    axios({
        url: '/api/Img/UpImg',
        method: 'post',
        data: f
    })
        .then((res) => {
            a.DoorLogo = res.data
        })
}

</script>

<style scoped></style>